package com.lzjy.tw.composedemo.domain.converter

import androidx.room.TypeConverter
import com.google.gson.reflect.TypeToken
import com.lzjy.tw.composedemo.domain.model.TestModel
import com.lzjy.tw.composedemo.utils.GsonInstance

class TestConverter {
    @TypeConverter
    fun objectToString(list: List<TestModel.SonModel>?): String? {
        return GsonInstance.instance?.gson!!.toJson(list)
    }

    @TypeConverter
    fun stringToObject(str: String?): List<TestModel.SonModel>? {
        val listType = object : TypeToken<List<TestModel.SonModel>>() {}.type
        return GsonInstance.instance?.gson!!.fromJson(str, listType)
    }
}